﻿using System;
using SFML.Graphics;
using SFML.Window;

namespace Discipulus
{
	class Game
	{
		public static RenderWindow Window;
		
		public static event EventHandler Initialized;
		public static event EventHandler Drawn;
		public static event EventHandler Updated;
		
		private static Color clearColor = new Color(100, 149, 237);
		
		public Game()
		{
			Window = new RenderWindow(new VideoMode(1280, 768), "Discipulus");
			
			// Initialization done.
			
			Window.Closed += OnClose;
			
			if (Initialized != null)
				Initialized(this, null);
			
			// Temporary code for testing the frame.
			
			new Frame(new IntRect(32, 32, 160, 160));
			
			// The main loop.
			
			while (Window.IsOpened())
				OnUpdate();
		}

		private void OnDraw()
		{
			Game.Window.Clear(clearColor);
			
			if (Game.Drawn != null)
				Game.Drawn(this, null);
			
			Game.Window.Display();
		}

		private void OnUpdate()
		{
			Window.DispatchEvents();

			if (Updated != null)
				Updated(this, null);
			
			OnDraw();
		}

		private void OnClose(object s, EventArgs e)
		{
			Window.Close();
		}
	}
}